package com.example.myapplication;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class MainActivityB extends AppCompatActivity {

    Button button_b;
    Button button_b2;
    TextView textView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //EdgeToEdge.enable(this);
        setContentView(R.layout.activity_main_b);
        /*ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });*/

        button_b = findViewById(R.id.buttonB1);
        button_b.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivityB.this,MainActivityA.class);
                intent.putExtra("result1","sssssss");
                setResult(666,intent);

                finish();       //运行完后关掉B
            }
        });

        button_b2 = findViewById(R.id.buttonB2);
        button_b2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivityB.this,MainActivityA.class);
                intent.putExtra("result2","aaaaaaa");
                setResult(777,intent);

                finish();       //运行完后关掉B
            }
        });


        textView = findViewById(R.id.textViewB1);
        String str = getIntent().getStringExtra("name");

        textView.setText(str);      //显示str的内容
    }
}